package com.example.administrator.x2picturetransliteration.Home.Adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import com.example.administrator.x2picturetransliteration.Base.BaseListViewAdapter;
import com.example.administrator.x2picturetransliteration.R;
import com.example.administrator.x2picturetransliteration.Util.Img.PicassoEqualProportionTransformation2;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * 意见反馈
 * Created by Administrator on 2019/8/28.
 */

public class FeedbackAdapter extends BaseListViewAdapter{

    private List<String> path;

    public FeedbackAdapter(Context context,List<String> path) {
        super(context);

        this.path = path;
    }

    @Override
    public int getLayoutView() {
        return R.layout.home_item_feedback;
    }

    @Override
    public int mCount() {
        return path.size();
    }

    @Override
    public void logic(ViewHolder mViewHolder, View view, final int position) {

        IViewHolder mIViewHolder = (IViewHolder)mViewHolder;

        Picasso.with(context)
                //.load("file://" +  path.get(position))
                .load(path.get(position))
                .placeholder(R.drawable.home_advertisement)
                .error(R.drawable.home_advertisement)
                .transform(new PicassoEqualProportionTransformation2(mIViewHolder.img))
                .into(mIViewHolder.img);


        mIViewHolder.deleteImg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                path.remove(position);
                FeedbackAdapter.this.notifyDataSetChanged();
            }
        });

    }

    @Override
    public ViewHolder InstantiationView(View mview) {

        IViewHolder mIViewHolder = new IViewHolder();

        mIViewHolder.img = mview.findViewById(R.id.img);
        mIViewHolder.deleteImg = mview.findViewById(R.id.deleteImg);

        return mIViewHolder;
    }

    private class IViewHolder extends ViewHolder{

        ImageView img; //图片
        ImageView deleteImg; //删除

    }
}
